/*
 * 文件名：LocalIndexEquipmentController.java	 
 * 时     间：下午12:31:48
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.controller.index;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.threads.UploadEquipmentRunble;
import com.cz073586.tools.util.ThreadPoolUtil;
import com.local.manager.cfgManager.CloudConfigManager;
import com.local.model.LocalEquipment;
import com.local.service.face.LocalEquipmentService;
import com.local.service.face.LogService;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;

/** 
 * 类描述:这里是类描述
 * @ClassName: LocalIndexEquipmentController 
 * @author Administrator
 * @date 2015年7月16日 下午12:31:48 
 */

@RestController
@RequestMapping(value = "/index/equipment", method = RequestMethod.POST)
public class LocalIndexEquipmentController extends BaseController
{
	
	@Autowired
	private LocalEquipmentService localEquipmentService;
	
	@Autowired
	private LogService logService;
	
	@RequestMapping(value = "/registerEquipment.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap registerEquipment(@RequestBody LocalEquipment equipment)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipmentService.registerEquipment(equipment);
			
			//TODO zhangwei 不上报设备信息到云,相机每5秒上报一次.
//			if (CloudConfigManager.instance().isOpen())
//			{
//				UploadEquipmentRunble upload = new UploadEquipmentRunble(
//						equipment, logService);
//				ThreadPoolUtil.instance().execute(upload);
//			}
			
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/viewEquipment.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap viewEquipment(@RequestBody LocalEquipment localEquipment)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localEquipment = localEquipmentService.findUniqueEquipment(localEquipment.getEquipmentUuid()
				);
			resultMap.put(CommonContans.STRUTS_DATA, localEquipment);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
}
